package perso.marcr.lst.spring3.controller;

import org.springframework.ui.Model;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

public class ParentController {

	private static final String TOKEN_ERROR= "error";

	public ParentController(Class<?> clazz)
	{
		System.out.println("LOADING: "+clazz.getCanonicalName());
	}

	/**
	 * @param message
	 * @param model
	 */
	protected void addError(String message, Model model)
	{
		model.addAttribute(TOKEN_ERROR, message);
	}


	/**
	 * @param ex
	 * @param model
	 */
	protected void addError(Exception ex, Model model)
	{
		addError(ex.getMessage(), model);
	}

	/**
	 * @param message
	 * @param model
	 */
	protected void addError(String message, RedirectAttributes model)
	{
		model.addFlashAttribute(TOKEN_ERROR, message);
	}

	/**
	 * @param ex
	 * @param model
	 */
	protected void addError(Exception ex, RedirectAttributes model)
	{
		addError(ex.getMessage(), model);
	}

}
